{block name="main"}

<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
    </script>

    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="{:url('admin/index/index')}">首页</a>
        </li>

        <li>
            节点管理
        </li>
        <li class="active">添加栏目</li>
    </ul><!-- .breadcrumb -->

</div>
<div class="container" style="margin-top: 30px;">
<div class="row">
    <div class="col-xs-12">
        <!-- PAGE CONTENT BEGINS -->
        <form class="form-horizontal" id="add-form"  role="form">
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="cname"> 栏目名称： </label>
                <div class="col-sm-9">
                    <input type="text" id="cname" placeholder="名称" onblur="reName();" name="cname" class="col-xs-10 col-sm-5" />
                    <span class="help-inline col-xs-12 col-sm-7">
                        <span class="middle"></span>
                    </span>
                </div>
            </div>

            <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right"> 父类栏目： </label>
            <div class="col-sm-9 col-md-3">
                <select class="form-control" name="pid" id="pid">
                    <option value="0">顶级栏目</option>
                    {volist name="data" id="cate"}
                    <option value="{$cate.id}">{:str_repeat('&nbsp;', $cate['count'] * 8).'|--'.$cate['cname'];}</option>
                    {/volist}
                </select>
            </div>
        </div>




            <div class="clearfix">
                <div class="col-md-offset-3 col-md-9">
                    <button class="btn btn-info btn-doadd" type="button">
                        <i class="icon-ok bigger-110"></i>
                        提交
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
</div>
        <script>

            $(function(){
                $('#cname').focus();
            });

            function reName(){
                var cname = $('#cname').val();
                if(!/^([a-zA-Z0-9\u4e00-\u9fa5\·]{1,10})$/.test(cname)){
                    $('.middle').eq(0).html('不能包含特殊符号。1到10字符').css({'color': 'red'});
                    return false;
                }else{
                    $('.middle').eq(0).html('正确').css({'color': 'green'});
                    return true;
                }
            }

            $('.btn-doadd').click(function(){
                if(reName()){
                    var cname = $('#cname').val();
                    var pid = $('#pid').val();

                    $.ajax({
                        type : 'post',
                        data : {'cname':cname,'pid':pid},
                        url : "/category",
                        success : function(data){
                            if(data.status){
                                alert('添加成功');
                                $('#showcate').click();
                            }else{
                                alert('添加失败');
                            }
                        },
                        error : function(){
                            alert('请求失败');
                        }
                    });
                }else{
                    alert('验证不通过');
                }

            });
        </script>


        {/block}